﻿@using Think9.Models;
@model Think9.Models.TbEventCustomizeEntity
@{ ViewBag.Title = "Add";
    Layout = "~/Areas/Shared/_LayuiForm.cshtml"; }

<form class="layui-form" lay-filter="formUser">
    <input style="display:none" id="tbid" value="@ViewBag.tbid">
    <div class="layui-form-item">
        <label class="layui-form-label required">类别</label>
        <div class="layui-input-block">
            <select id="EventId" name="EventId" lay-verify="required" lay-filter="selectEventId">
                @foreach (valueTextEntity item in ((List<valueTextEntity>)ViewBag.SelectList))
                {

                    <option value="@item.Value">@item.Text</option>
                }
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">名称</label>
        <div class="layui-input-block">
            <input type="text" name="FullName" id="FullName" placeholder="请输入名称" autocomplete="off" class="layui-input" lay-verify="required" maxlength="30">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">SQL语句</label>
        <div class="layui-input-block">
            <textarea style="border:0;border-radius:5px;background-color:rgba(241,241,241,.98);height: 150px;padding: 10px;" class="layui-textarea" id="ExecuteSql" name="ExecuteSql" lay-verify="required" placeholder='自定义包含参数的SQL语句实现DELETE、INSERT、UPDATE操作，点击下列按钮可设置操作'></textarea>
            <span style="position: absolute;top: 0px; left: 0px;">
                <i class="fa fa-question-circle-o" style="color: #FE7300;" lay-tips="tips" data-offset="4" id="tipsSql"></i>
            </span>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-inline"><button type="button" class="layui-btn-primary layui-btn-sm" id="insert" style="color:#FE7300"><i class="fa fa-code"></i>Insert</button>&nbsp;<button type="button" class="layui-btn-primary layui-btn-sm" id="update" style="color:#FE7300"><i class="fa fa-code"></i>Update</button>&nbsp;<button type="button" class="layui-btn-primary layui-btn-sm" id="delete" style="color:#FE7300"><i class="fa fa-code"></i>Delete</button></div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea class="layui-textarea" id="Remarks" name="Remarks" placeholder='请输入备注'></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">序号</label>
        <div class="layui-input-block">
            <input type="text" name="OrderNo" id="OrderNo" placeholder="排序-按照序号顺序执行" autocomplete="off" class="layui-input" lay-verify="required|number" maxlength="3">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="add">新 建</button>
        </div>
    </div>
</form>

<script>
    layui.use(["form", "exLayer", "exUtils", "layer", "code"], function () {
        let form = layui.form;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        let tableSelect = layui.tableSelect;
        let layer = layui.layer;

        let $ = layui.$;

        form.render(); //

        form.on("submit(add)", function (data) {
            exUtils.ajax("/SysTable/TbEvent/Add", "post", { model: data.field, tbid: $("#tbid").val() }, true).done(function (response) {
                exLayer.greenTickMsg(response.message, function () {
                    parent.layui.table.reload('tableId', { url: "/SysTable/TbEvent/GetList?tbid=" + $("#tbid").val() });
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }).fail(function (error) {
                console.log(error);
            });
            return false;
        });

        //下拉选择
        form.on('select(selectEventId)', function (data) {

        })

        $("#insert").click(function () {
            exLayer.openMiddle("", "/SysTable/TbEvent/TempletInsert?tbid=" + $("#tbid").val(), '600px', '400px', layui.device().mobile);
        });

        $("#update").click(function () {
            exLayer.openMiddle("", "/SysTable/TbEvent/TempletUpdate?tbid=" + $("#tbid").val(), '600px', '400px', layui.device().mobile);
        });

        $("#delete").click(function () {
            exLayer.openMiddle("", "/SysTable/TbEvent/TempletDelete?tbid=" + $("#tbid").val(), '600px', '400px', layui.device().mobile);
        });

        function GetTips(some) {
            var _return = "";
            $.ajax({
                url: "/SysTable/TbIndex/GetTbIndexTips",
                type: "post",
                data: { str: some },
                dataType: "json",
                async: false,
                success: function (result) {
                    _return = result;
                }
            });
            return _return;
        };

        //消息提示
        $(document).on("mouseenter", "#tipsSql", function () {
            var remind = GetTips($('#ExecuteSql').val());
            var tips = $(this).data("offset") || 4;
            var color = $(this).data("color") || '#88858e';
            layer.tips(remind, this, {
                time: -1,
                tips: [tips, color],
                area: ['auto', 'auto'],
            });
        }).on("mouseleave", "#tipsSql", function () {
            layer.closeAll("tips");
        });

        $(document).ready(function () {
            if (layui.device().mobile) {
                $(".layui-inline").attr('class', 'layui-input-inline');
            }
        });
    });
</script>